package com.letv.android.client.episode.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.letv.android.client.activity.AlbumPlayActivity;
import com.letv.android.client.episode.PlayAlbumController;
import com.letv.android.client.episode.adapter.DetailHalfPlayExpandableListAdapterPlayerLibs;
import com.letv.android.client.episode.adapter.DetailHalfPlayExpandableListByDateAdapterPlayerLibs;
import com.letv.android.client.episode.adapter.DetailVideosGridAdapterPlayerLibs;
import com.letv.android.client.episode.adapter.NewDetailHalfVideosListAdapter;
import com.letv.android.client.episode.widget.HalfMaxHeightListViewPlayerLibs;
import com.letv.android.client.episode.widget.PinnedHeaderExpListView;
import com.letv.android.client.fragment.LetvBaseFragment;
import com.letv.android.client.view.LoadingDialog;
import com.letv.android.client.view.PublicLoadLayout;
import com.letv.android.young.client.R;
import com.letv.core.bean.AlbumNew;
import com.letv.core.bean.VideoBean;

import java.util.ArrayList;

//import com.letv.android.client.LetvApplication;
//import com.letv.android.client.episode.request.RequestTopicVideoListTask;
//import com.letv.android.client.ui.download.BaseDownloadFragment;
//import com.letv.android.client.utils.CursorLoader;

@SuppressLint("ValidFragment") 
public class HalfPlayVideosFragment extends LetvBaseFragment {

    /*
     * 从全屏还是半屏进入剧集下载页面
     */
    public static final String EPISODE_FULL_SCREEN_DOWNLOAD_KEY = "episode_full_screen_download_key";


    /*
     * 当前显示的剧集类型
     */
    public static final String CURRENT_SHOW_STYLE = "current_show_style";    

    /*
     * 剧集每行可容纳的数目
     */
    public static final int VIDEO_NUMBER_IN_ONE_ROW = 5;

    /*
     * 剧集列表项类型
     */
    public static final int VIDEO_EPISODE_ITEM = 1;
    public static final int VIDEO_EPISODE_SURROUND_TITLE = 2;
    public static final int VIDEO_EPISODE_SURROUND_ITEM = 3;
    /*
     * 剧集类型总数
     */
    public static final int VIDEO_EPISODE_ITEM_TOTAL = 4;

    // 1:九宫格 2:长列表 3:按期数 4:专题视频剧集列表
    private static final int GRIDVIEW_LIST_CONSTANT = 1;
    private static final int VIDEO_LIST_CONSTANT = 2;
    private static final int EXPAND_LIST_CONSTANT = 3;
    public static final int TOPIC_VIDEO_LIST_CONSTANT = 4;
    private static final int TOPIC_VIDEO_ITEM_LIST_CONSTANT = 5;

    private static final String GRIDVIEW_LIST_CONSTANT_STR = "1";
    private static final String VIDEO_LIST_CONSTANT_STR = "2";
    private static final String TOPIC_VIDEO_ITEM_LIST_CONSTANT_STR = "5";
   
    /*
     * GridView 在半屏/全屏中的显示列数
     */
    private static final int GRIDVIEW_NUMCOLUMNS_HALF = 5;
    private static final int GRIDVIEW_NUMCOLUMNS_FULL = 4;

    private static final String TAG = "HalfPlayVideosFragment";

    private PlayAlbumController playAlbumController;

    private PublicLoadLayout root;

    private LinearLayout videoRootLayout;

    /**
     * 当前视频在列表中第几个位置,
     * */
    private int videoInListPosition = 0;

    /**
     * 剧集列表 宫格形势
     */
    private GridView videosGridView;
    
    private ScrollView scrollView;

    /**
     * 宫格适配器 播放
     */
    private DetailVideosGridAdapterPlayerLibs gridAdapter;

    /**
     * 列表适配器
     */
    private NewDetailHalfVideosListAdapter allListAdapter;

    /**
     * 翻页position
     * */
    private int updateGroupPosition = -1;

    /**
     * 显示集数（<60集才显示）
     */
    private RelativeLayout detailplayHalfVideoLayout;
    private TextView videosNumTView;
    private TextView jumpDescView;
    private TextView jumpArrowView;

    /**
     * 是否有签到浮球
     */
    private boolean hasAttendance;

    /**
     * 周边视频 view
     */
    private TextView surroundVideosCounts;// 周边视频数目

    /**
     * 全屏展示集数
     */
    private TextView fullEpisodeNumView;
    private ListView surroundListView;// 周边视频列表
    private NewDetailHalfVideosListAdapter surroundListAdapter;// 周边视频列表适配器

    private ArrayList<VideoBean> surroundVideoList;
    private PinnedHeaderExpListView halfEpisodeExpandListView;
    private HalfMaxHeightListViewPlayerLibs halfMaxHightListView;
    private DetailHalfPlayExpandableListAdapterPlayerLibs halfEpisodeExpandListViewAdapter;
    private DetailHalfPlayExpandableListByDateAdapterPlayerLibs halfEpisodeExpandListViewByDateAdapter;

    private TextView surroundVideosHeaderBeforeExpListView;

    /*
     * GridView + ListView 下的五屏logo
     */
    private ImageView fiveScreenLogoImageView;

    /*
     * ExpandableListView + ListView 下的五屏logo
     */
    private ImageView fiveScreenLogoImageViewExp;


    /**
     * 统计添加：周边视频标识
     */
    public static boolean issurroundItemClick = false;

    /*
     * PinnedListView下方的Listview layout
     */
    private View mPinnedFooterView;

    /*
     * ListView上方的HeaderView layout
     */
    private View mListViewHeaderView;

    private Runnable mScrollRunnable = null;
    private Runnable mScrollRunnable1 = null;
    private Runnable mScrollRunnable2 = null;
    private Runnable mScrollRunnable3 = null;

    private Handler mHandler = new Handler(Looper.getMainLooper());

    /*
     * New Added by chenhong on 2015-04-26 from version 5.8.1
     */
    private int mCurrentStyle = -1;

    private LoadingDialog mLoadingDialog;

    /*
     * 所有的List列表的数据集合
     */
    private ArrayList<VideoBean> mAllDataList = null;

    /*
     * 所有可在当前页面中可播放的剧集列表
     */
    private ArrayList<VideoBean> mVideoListBean = new ArrayList<VideoBean>();
    
    /**
     * 一页的条数
     */
    public int pageSize = 100;

    /* 是否能够下载
     * 当前是从半屏/全屏 进入剧集下载入口进入剧集显示页面
     * 默认值-1时进入点击Item项进行播放
     */
    // private int isDownload = -1; //EPISODE_SCREEN_DOWNLOAD_FULL;
    private boolean isDownload = false;

    /*
     * 是专辑还是视频
     */
    private int type = AlbumNew.Type.VRS_MANG;    
    
    /*
     * 请求专题视频列表
     */
//    private RequestTopicVideoListTask mRequestTopicVideoListTask;
    
    private AlbumPlayActivity mActivity;
    
    /*
     * 专题视频宫格数据Bean对象
     */
    private ArrayList<VideoBean> mVideoGridBean = new ArrayList<VideoBean>();

    /*
     * 是从点播还是专题进入播放页面
     */
    // private int mLaunchMode = LAUNCH_MODE_ALBUM;
    
    
    /*
     * 布局文件中ViewStub填充后的View，
     * 分别指向ExpandableListView, ListView, GridView的Layout View
     */
    private View mExpandableListLayoutView = null; //暂未使用
    private View mListLayoutView = null;
    private View mGridLayoutView = null;

    /**
     * 是否全屏中展示，不能通过 { UIs.isLandscape(context) }来判定，屏幕横屏时，下半屏幕的ListView仍然需要显示竖屏布局
     */
    public boolean isLandscape = false;
    
    private boolean isShowingWatch;  //是否确定展示看点    

    /*
     * 是否为专题切换专辑的剧集页面展示
     * 默认为false 
     */
    private boolean mIsTopicVlistFlag = false;

    private int vid;

    @SuppressLint("ValidFragment")
    public HalfPlayVideosFragment(int vid){
        this.vid = vid;
    }

    public HalfPlayVideosFragment(){
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        mActivity = (AlbumPlayActivity) activity;
    }

    // public void setArguments(int flag) {
    // mHalfFullFlag = flag;
    // }

    /**
     * When creating, retrieve this instance's number from its arguments.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        root = PublicLoadLayout.createPage(getActivity(), R.layout.letv_detail_half_surround_list_playerlibs);
        
        return root;
    }

    
    
   

	@Override
	public String getTagName() {

		return null;
	}

	@Override
	public int getContainerId() {

		return 0;
	}

	
    
    
}
